package com.lin.eat.controller;

import com.lin.eat.entry.ServerResponse;
import com.lin.eat.entry.ShoppingCar;
import com.lin.eat.entry.ShoppingCarDetail;
import com.lin.eat.serivce.ShoppingCarService;
import com.lin.eat.util.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@CrossOrigin    //跨域
@RestController
public class ShoppingCarController {

    @Autowired
    private ShoppingCarService shoppingCarService;

    /**
     * 加入购物车
     * @param shoppingCar
     * @return
     */
    @PostMapping("/addShoppingCar")
    public ServerResponse addShoppingCar(@RequestBody ShoppingCar shoppingCar){
        return shoppingCarService.addShoppingCar(new ShoppingCar(UuidUtil.createUUID(),shoppingCar.getG_id(),shoppingCar.getS_number()));
    }

    /**
     * 从购物车删除某商品
     * @param g_id
     * @return
     */
    @GetMapping("/deleteShoppingCar/{g_id}")
    public ServerResponse deleteShoppingCar(@PathVariable("g_id") String g_id){
        return shoppingCarService.deleteShoppingCar(g_id);
    }

    /**
     * 修改购物车中某个商品的选中状态
     * @param shoppingCar
     * @return
     */
    @PostMapping("/updateShoppingCarState")
    public ServerResponse updateShoppingCarState(@RequestBody ShoppingCar shoppingCar){
        return shoppingCarService.updateShoppingCarState(shoppingCar);
    }

    /**
     * 修改购物车中所有商品的选中状态
     * @param s_state
     * @return
     */
    @GetMapping("/updateAllShoppingCarState/{s_state}")
    public ServerResponse updateAllShoppingCarState(@PathVariable("s_state") String s_state){
        return shoppingCarService.updateAllShoppingCarState(s_state);
    }

    /**
     * 获取购物车列表
     * @return
     */
    @GetMapping("/getShoppingCarInfo")
    public ServerResponse<List<ShoppingCarDetail>> getShoppingCarInfo(){
        return shoppingCarService.getShoppingCarInfo();
    }

    /**
     * 修改购物车某个商品的数量
     * @param shoppingCar
     * @return
     */
    @PostMapping("/updateShoppingCarNumber")
    public ServerResponse updateShoppingCarNumber(@RequestBody ShoppingCar shoppingCar){
        return shoppingCarService.updateShoppingCarNumber(shoppingCar);
    }

    /**
     * 获取购物车中选中的商品
     * @return
     */
    @GetMapping("/getShoppingCarChecked")
    public ServerResponse<List<ShoppingCarDetail>> getShoppingCarChecked(){
        return shoppingCarService.getShoppingCarChecked();
    }


}
